package plgutils

import (
	"dgo/goutils/utils"
	"gitee.com/ymofen/supervalue"
)

type PlgSyncMap struct {
	PlgBase
	lstMap utils.GSyncMapGroup
}

func NewPlgSyncMap() *PlgSyncMap {
	rval := &PlgSyncMap{}
	return rval
}

func CreatePlgSyncMapFunc(args ...interface{}) (rval interface{}, err error) {
	obj := NewPlgSyncMap()
	if len(args) > 0 {
		if str, ok := args[0].(string); ok {
			obj.PlugId = str
		}
	}
	rval = obj
	return
}

/*
*

	{
	  "id":"sycmap",
	  "type":"utils.sync.map",
	  "conf":{}
	}
*/
func (this *PlgSyncMap) ReloadConf(conf *wrapper.SuperValue) error {
	return nil
}

func (this *PlgSyncMap) LoadOrStore(id interface{}, store interface{}) (actual interface{}, loaded bool) {
	return this.lstMap.LoadOrStore(id, store)
}

func (this *PlgSyncMap) RemoveAndGet(id interface{}) (val interface{}, ok bool) {
	return this.lstMap.RemoveAndGet(id)
}

func (this *PlgSyncMap) Range(f func(key, value interface{}) bool) {
	this.lstMap.Range(f)
}

func (this *PlgSyncMap) Set(id interface{}, val interface{}) {
	this.lstMap.Set(id, val)
}

func (this *PlgSyncMap) Get(id interface{}, def interface{}) interface{} {
	return this.lstMap.Get(id, def)
}

func (this *PlgSyncMap) Count() int {
	return this.lstMap.Count()
}
